package com.wimcorp.magic.abilities;

import java.rmi.RemoteException;

import javax.persistence.Entity;
import javax.persistence.Table;

import com.wimcorp.magic.abilities.trigger.AbilityTrigger;
import com.wimcorp.magic.exception.CastException;
import com.wimcorp.magic.input.Target;

/**
 * example {target: 'SELF', amount:'2'}
 * 
 * target options : SELF,OPPONENT
 * 
 * amount
 */
@Entity
@Table(name = "life", schema = "abilities")
public class Life extends Ability {

	private int amount;
	
	protected Life() {
	}

	public Life(AbilityTrigger trigger) {
		super(trigger);
	}

	public Life(Life ability) {
		super(ability);
		this.amount= ability.getAmount();
	}

	@Override
	protected void executeAbility() throws CastException {

		switch (getTarget()) {
		case SELF:
			if (amount > 0) {
				getPlayer().addLife(amount);
			}else{
				getPlayer().subtractLife(amount*-1);
			}
			break;
		case OPPONENT:
			if (amount > 0) {
				getPlayer().getOpponent().addLife(amount);
			}else{
				getPlayer().getOpponent().subtractLife(amount*-1);
			}
			break;
		}
	}

	@Override
	public Life clone() {
		return new Life(this);
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}
	
	
	
	
}
